﻿using System;

namespace ProjetCom.Model.Template
{
    class Balle : Element
    {
        private int m_StepH;
        private int m_StepV;

        public int StepV
        {
            get { return m_StepV; }
            set { m_StepV = value; }
        }

        public int StepH
        {
            get { return m_StepH; }
            set { m_StepH = value; }
        }

        public Balle(int p_x, int p_y, int p_StepH, int p_StepV)
            : base(p_x, p_y)
        {
            m_name = "Balle";
            m_StepH = p_StepH;
            m_StepV = p_StepV;
        }

        override public void Update(Microsoft.Xna.Framework.GameTime _gameTime)
        {
            m_x += m_StepH * ((double)_gameTime.ElapsedGameTime.Milliseconds / 100);
            m_y += m_StepV * ((double)_gameTime.ElapsedGameTime.Milliseconds / 100);
        }
        
        override public CoteCollision EnterCollision(Element Other)
        {
            Element.CoteCollision coteColl =  Other.EnterCollision(this);

            switch (coteColl)
            {
                case CoteCollision.bottom:
                    return CoteCollision.top;
                case CoteCollision.top:
                    return CoteCollision.bottom;
                case CoteCollision.right:
                    return CoteCollision.left;
                case CoteCollision.left:
                    return CoteCollision.right;
                default:
                    return CoteCollision.none;
            }
        }

        override public void Collision(CoteCollision p_cote, Boolean p_moove = false)
        {
            if (p_cote == CoteCollision.bottom)
            {
                m_y = (m_y < 0) ? 0 : m_y;
                m_StepV *= -1;
            }
            else if(p_cote == CoteCollision.top)
            {
                m_y = (m_y > 720) ? 720 : m_y;
                m_StepV *= -1;
            }
            else if (p_cote == CoteCollision.right)
            {
                m_StepH *= -1;
            }
            else if (p_cote == CoteCollision.left)
            {
                m_StepH *= -1;
            }
        }
    }
}
